# -*- coding:utf-8 -*-
import re


class StrUtil:

    # 驼峰转下划线
    @staticmethod
    def camel_to_snake(camel_case):
        snake_case = re.sub(r'(?<!^)(?=[A-Z])', '_', camel_case).lower()
        return snake_case

    # 下划线转驼峰
    @staticmethod
    def snake_to_camel(snake_case):
        components = snake_case.split('_')
        camel_case = components[0] + ''.join(x.title() for x in components[1:])
        return camel_case

    @staticmethod
    def remove_all_newlines(text: str) -> str:
        """
        去除字符串中所有类型的换行符（包括\n、\r\n、\r）

        :param text: 包含换行符的原始字符串
        :return: 去除所有换行符后的字符串
        """
        if not isinstance(text, str):
            raise TypeError("输入必须是字符串类型")

        # 替换所有可能的换行符为空白
        # \n: Unix/Linux/macOS换行符
        # \r: 早期Mac OS换行符
        # \r\n: Windows换行符
        return text.replace('\n', '').replace('\r', '')

    def __init__(self):
        pass
